﻿namespace PowerSong.UserInterface
    {
    using System.ComponentModel;
    using System.Windows.Media;
    using System.Windows;

    public class PlayListItemModel : INotifyPropertyChanged
        {

        public event PropertyChangedEventHandler PropertyChanged;

        public ServiceItem Data { get; private set; }

        #region IsActive Property

        private bool isActive = default(bool);

        public bool IsActive
            {
            get
                {
                return isActive;
                }
            set
                {
                isActive = value;
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("IsActive"));
                this.Background = value == true ? Brushes.Black : SystemColors.MenuBrush;
                this.Foreground = value == true ? Brushes.White : SystemColors.MenuTextBrush;
                }
            }

        #endregion

        #region Background Property

        private Brush background = SystemColors.MenuBrush;

        public Brush Background
            {
            get
                {
                return background;
                }
            private set
                {
                background = value;
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Background"));
                }
            }

        #endregion

        #region Foreground Property

        private Brush foreground = SystemColors.MenuTextBrush;

        public Brush Foreground
            {
            get
                {
                return foreground;
                }
            private set
                {
                foreground = value;
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Foreground"));
                }
            }

        #endregion

        #region TileBackground Property

        private Brush tileBackground = default(Brush);

        public Brush TileBackground
            {
            get
                {
                return tileBackground;
                }
            set
                {
                tileBackground = value;
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("TileBackground"));
                }
            }

        #endregion

        #region Title Property

        private string title = default(string);

        public string Title
            {
            get
                {
                return title;
                }
            set
                {
                title = value;
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Title"));
                }
            }

        #endregion

        #region Subtitle Property

        private string subtitle = default(string);

        public string Subtitle
            {
            get
                {
                return subtitle;
                }
            set
                {
                subtitle = value;
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Subtitle"));
                }
            }

        #endregion

        public PlayListItemModel(ServiceItem data, bool isActive)
            {
            this.Data = data;
            this.Title = data.ToString();

            // Show selected state
            this.IsActive = isActive;
            
            // Is there style information?
            if (data is IStyledServiceItem)
                {
                var styleDetails = (IStyledServiceItem)data;
                this.TileBackground = new SolidColorBrush(styleDetails.Style.BackgroundColor.ToColor());

                // Show the style name being used, and whether or not it has been overridden
                this.Subtitle = string.Format("Style: {0}", styleDetails.Style.Name);
                if (styleDetails.StyleOverride != null)
                    {
                    this.TileBackground = styleDetails.StyleOverride.Colour;
                    this.Subtitle += " (Customised)";                    
                    }

                }

            // Show what type of special item this is, if the item is a special type of item
            if (data is VideoServiceItem) this.Subtitle = "Video";
            if (data is BannerServiceItem) this.Subtitle = "Scrolling Notice";

            }

        }

    }
